import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../views/Login"
import Blogs from "../views/Blogs"
import BlogDetail from "../views/BlogDetail"
import BlogEdit from "../views/BlogEdit"

Vue.use(VueRouter)

const routes = [
    {
        // 博客列表
        path: '/',
        name: 'Index',
        redirect: {name: 'Blogs'}
    },
    {
        // 博客列表
        path: '/blogs',
        name: 'Blogs',
        component: Blogs
    },
    {
        // 登录页面
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        // 添加博客
        // 注意放在 path: '/blog/:blogId'之前
        path: '/blog/add',
        name: 'BlogAdd',
        component: BlogEdit,
        meta: {
            // 添加该字段，表示进入这个路由是需要登录的（requireAuthentication）
            requireAuth: true
        }
    },
    {
        // 博客详情页
        path: '/blog/:blogId',
        name: 'BlogDetail',
        component: BlogDetail
    },
    {
        // 修改博客
        path: '/blog/:blogId/edit',
        name: 'BlogEdit',
        component: BlogEdit,
        meta: {
            requireAuth: true
        }
    },
    {
        // 测试element-ui
        path: '/demo',
        name: 'Demo',
        // 懒加载
        component: () => import('../views/Demo.vue')
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router
